# Maintainer: Ilya Rakhlin <i.rakhlin@gmail.com>

_realname=pkgconf
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.7.3
pkgrel=5
pkgdesc='pkg-config compatible utility which does not depend on glib'
url='https://github.com/pkgconf/pkgconf'
arch=('any')
license=('ISC')
options=('!debug' 'strip')
provides=("${MINGW_PACKAGE_PREFIX}-pkg-config")
conflicts=("${MINGW_PACKAGE_PREFIX}-pkg-config")
replaces=("${MINGW_PACKAGE_PREFIX}-pkg-config")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-ninja")
groups=("${MINGW_PACKAGE_PREFIX}-toolchain")
source=(https://distfiles.dereferenced.org/pkgconf/$_realname-$pkgver.tar.gz
        0001-meson-write-pc-file.patch
        0003-size-t-format.patch
        0004-fix-prefix-dirsep.patch
        0005-fix-version-validate.patch
        0006-printf-format.patch)
sha256sums=('d040859b36880323209f347c7c936e40a748ee63e123e43a771791a64165d6b1'
            '9af1f0600ca15e5f285ba54f4cb334f5d7e00f1bc21b6f571d71acd747f303b6'
            '1db5975d6b1db946ba1d71cc3cf390dec567899a89d7ef53f56f24f0058cdbe3'
            '8b2dd7551f9d6be9b202718fdcc6c526c5557831a703b617fc862a609be14450'
            'bddc97d669f7eda5d0e5b4fa023d684c394ff0f1cd5c9ccc38ecb514d9be2809'
            'a7efeef61b4af1c0813d9d8a211cde669a3e3fa2c97ed21e55487667769c567a')

prepare() {
  cd ${srcdir}/$_realname-$pkgver

  patch -p1 -i ${srcdir}/0001-meson-write-pc-file.patch
  patch -p1 -i ${srcdir}/0003-size-t-format.patch

  # properly convert paths to pc values and normalize dir seperators
  # while escaping spaces
  patch -p1 -i ${srcdir}/0004-fix-prefix-dirsep.patch

  patch -p1 -i ${srcdir}/0005-fix-version-validate.patch
  patch -p1 -i ${srcdir}/0006-printf-format.patch
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir ${srcdir}/build-${MINGW_CHOST}
  cd ${srcdir}/build-${MINGW_CHOST}

  MSYS2_ARG_CONV_EXCL="--prefix=" \
  ${MINGW_PREFIX}/bin/meson \
    --prefix="${MINGW_PREFIX}" \
    --buildtype=plain \
    -Dtests=false \
    ../${_realname}-${pkgver}

  meson compile
}

package() {
  cd ${srcdir}/build-${MINGW_CHOST}

  DESTDIR="${pkgdir}" meson install

  cp "${pkgdir}${MINGW_PREFIX}"/bin/pkgconf "${pkgdir}${MINGW_PREFIX}"/bin/pkg-config
  cp "${pkgdir}${MINGW_PREFIX}"/bin/pkgconf "${pkgdir}${MINGW_PREFIX}"/bin/${MINGW_CHOST}-pkgconf
  cp "${pkgdir}${MINGW_PREFIX}"/bin/pkg-config "${pkgdir}${MINGW_PREFIX}"/bin/${MINGW_CHOST}-pkg-config
}
